package org.molamil.acto.types {
	import org.molamil.acto.core.parsers.ParserError;	
	
	import flexunit.framework.TestCase;	
	
	/**
	 * @author Jorge Hernandez
	 */
	public class DateTypeParserTest extends TestCase {
		
		
		// PROPERTIES
		
		private var instance:DateTypeParser;
		
		
		// CONSTRUCTOR
		
		public function DateTypeParserTest(methodName:String = null) {
			super(methodName);
		}
		
		
		// PUBLIC METHODS
		
		override public function setUp():void {
			instance = new DateTypeParser();
		}
		
		override public function tearDown():void {
			instance = null;
		}
		
		public function testParse():void {
			
			assertEquals("'1979-10-21' parses", new Date(1979, 9, 21).getTime(), 
				(instance.parse("1979-10-21") as Date).getTime());
			assertEquals("'1979-12-31' parses", new Date(1979, 11, 31).getTime(), 
				(instance.parse("1979-12-31") as Date).getTime());
			assertEquals("'1979-01-31' parses", new Date(1979, 0, 31).getTime(), 
				(instance.parse("1979-01-31") as Date).getTime());
			assertEquals("'1979-10-21 09' parses", new Date(1979, 9, 21, 9).getTime(), 
				(instance.parse("1979-10-21 09") as Date).getTime());
			assertEquals("'1979-10-21 10' parses", new Date(1979, 9, 21, 10).getTime(), 
				(instance.parse("1979-10-21 10") as Date).getTime());
			assertEquals("'1979-10-21 00' parses", new Date(1979, 9, 21, 0).getTime(), 
				(instance.parse("1979-10-21 00") as Date).getTime());
			assertEquals("'1979-10-21 24' parses", new Date(1979, 9, 21, 24).getTime(), 
				(instance.parse("1979-10-21 24") as Date).getTime());
			assertEquals("'1979-10-21 09:15' parses", new Date(1979, 9, 21, 9, 15).getTime(), 
				(instance.parse("1979-10-21T09:15") as Date).getTime());
			assertEquals("'1979-10-21T00:00' parses", new Date(1979, 9, 21, 0, 0).getTime(), 
				(instance.parse("1979-10-21 00:00") as Date).getTime());
			assertEquals("'1979-10-21T00:59' parses", new Date(1979, 9, 21, 0, 59).getTime(), 
				(instance.parse("1979-10-21T00:59") as Date).getTime());
			assertEquals("'1979-10-21 00:50:50' parses", new Date(1979, 9, 21, 0, 50, 50).getTime(), 
				(instance.parse("1979-10-21 00:50:50") as Date).getTime());
			
			assertEquals("'Sun Oct 21 09:00:00 GMT+0200 1979' parses", 
				new Date(1979, 9, 21, 9, 0, 0).getDate(), 
				(instance.parse("Sun Oct 21 09:00:00 GMT+0200 1979") as Date).getDate());
			
			try {
				instance.parse("1979-10");
				fail("'1979-10' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-20-21");
				fail("'1979-20-21' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-41");
				fail("'1979-10-41' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-1-31");
				fail("'1979-1-31' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 ");
				fail("'1979-10-21 ' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21T");
				fail("'1979-10-21T' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 25");
				fail("'1979-10-21 25' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 1");
				fail("'1979-10-21 1' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 30");
				fail("'1979-10-21 30' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 09:1");
				fail("'1979-10-21 09:1' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 00:");
				fail("'1979-10-21 00:' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 00:60");
				fail("'1979-10-21 00:60' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 00:60");
				fail("'1979-10-21 00:60' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse("1979-10-21 00:50:99");
				fail("'1979-10-21 00:50:99' should fail");
			} catch (e:ParserError) {}
			
			try {
				instance.parse(null);
				fail("null should fail");
			} catch (e:ParserError) {}
			
			
		}
		
		
	}
	
}
